#ifndef SANGAME_HISTORY_VIEW_H_
#define SANGAME_HISTORY_VIEW_H_

#include "base/message_loop.h"
#include "history/indicator_message.h"
#include "draw/Axes.h"

namespace sangame {
namespace history {

class CHistoryLayout;

class View : public base::MessageLoop {
public:
    enum Setting {
        TITLE_HEIGHT = 20,
        LEFT_YAXIS_WIDTH = 55,
        RIGHT_YAXIS_WIDTH = 55,
        START_STATUS_ID = 10,
    };

    View();
    ~View();

    #pragma region SG Message

public:
    bool OnSetRect(base::Rect* message_ptr);
    bool OnLButtonDown(base::MouseMessage* message_ptr);
    bool OnMessage(int message_type, void* message_ptr);

private:
    bool OnInitContext(ContextMessage* message_ptr);
    bool OnDrawBack(base::CanvasMessage* message_ptr);
    bool OnDrawFore(base::CanvasMessage* message_ptr);
    bool OnIndicatorOverlayChange(SGIndicatorOverlay* indicator_overlay_param);
    bool OnIndicatorGoodsChange(SGIndicatorGoods* indicator_goods_param);
    bool OnIndicatorArbitrageChange(SGIndicatorArbitrage* indicator_arbitrage_param);
    bool OnIndicatorServerChange(SGIndicatorServer* indicator_arbitrage_param);
    bool OnUpdateAxes();
    bool DispatchMessage(int message_type, void* message_ptr);
    bool DispatchMessageByType(int type, int message_type, void* message_ptr);

    #pragma endregion

    #pragma region Draw

protected:
    void DrawFrame(base::CanvasMessage* message_ptr);
    void DrawSelected(base::CanvasMessage* message_ptr);
    void DrawTitle(base::CanvasMessage* message_ptr);

    base::Rect view_area_;
    base::Rect title_area_;
    base::Rect y_coord_area_;
    base::Rect canvas_area_;

    #pragma endregion

    #pragma region XMLString Status

public:
    bool LoadXml(std::string& xml);
    bool SaveXml(std::string& xml);
    int GetStatusID();
    void OnStatusUpdate();

    struct Status {
        bool m_bMain;
        bool m_bSelected;
    } m_tStatus;

    #pragma endregion

    #pragma region SG Data

public:
    void SetType(int type);
    int GetType();
    CHistoryLayout* GetLayout();
    CAxes& GetAxes();

private:

    std::shared_ptr<Indicator> main_indicator_ptr_;
    std::vector<std::shared_ptr<Indicator>> overlay_indicator_ptr_list_;
    std::vector<std::shared_ptr<Indicator>> overlay_goods_ptr_list_;
    std::vector<std::shared_ptr<Indicator>> overlay_arbitrage_ptr_list_;
    std::shared_ptr<Indicator> server_indicator_ptr_;
    std::weak_ptr<Indicator> weak_selected_indicator_ptr_;
	Layout* layout_ptr;
    CAxes axes_;
    int indicator_type_;
    bool is_y_coord_left_;

    #pragma endregion

};

} // namespace history
} // namespace sangame

#endif // SANGAME_HISTORY_VIEW_H_